package cn.demo.um.controller;

import java.util.List;

import cn.demo.common.utils.SecurityUtils;
import cn.demo.um.support.model.MatchScoreDto;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.demo.common.enums.BusinessType;
import cn.demo.um.domain.UmClientUser;
import cn.demo.um.service.IUmClientUserService;
import cn.demo.common.utils.poi.ExcelUtil;
import cn.demo.common.core.page.PageR;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.paginate.Page;


/**
 * 客户端用户Controller
 *
 * @author xtjun
 * @date 2024-06-04
 */
@Tag(name = "客户端用户")
@RestController
@RequestMapping("/um/umClientUser")
public class UmClientUserController extends BaseController {
    @Resource
    private IUmClientUserService umClientUserService;

    @Operation(summary = "查询客户端用户列表")
    @PreAuthorize("@ss.hasPermi('um:umClientUser:list')")
    @GetMapping("/list")
    public PageR<UmClientUser> list(UmClientUser umClientUser, PageQuery pageQuery) {
        Page<UmClientUser> page = umClientUserService.selectUmClientUserPage(umClientUser, pageQuery);
        return PageR.ok(page);
    }

    @Operation(summary = "查询客户端用户列表")
    @PreAuthorize("@ss.hasPermi('um:umClientUser:list')")
    @GetMapping("/matchScoreList")
    public List<UmClientUser> matchScoreList(PageQuery pageQuery) {
        Integer pageNum = pageQuery.getPageNum();
        Integer pageSize = pageQuery.getPageSize();
        Integer start = (pageNum - 1) * pageSize;
        List<UmClientUser> scoreUsers = umClientUserService.matchFullScoreDtoList(SecurityUtils.getUserId(), start, pageSize);
        return scoreUsers;
    }

    @Operation(summary = "导出客户端用户列表")
    @PreAuthorize("@ss.hasPermi('um:umClientUser:export')")
    @Log(title = "客户端用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UmClientUser umClientUser) {
        List<UmClientUser> list = umClientUserService.selectUmClientUserList(umClientUser);
        ExcelUtil<UmClientUser> util = new ExcelUtil<UmClientUser>(UmClientUser.class);
        util.exportExcel(response, list, "客户端用户数据");
    }

    @Operation(summary = "获取客户端用户详细信息")
    @PreAuthorize("@ss.hasPermi('um:umClientUser:query')")
    @GetMapping(value = "/{id}")
    public R<UmClientUser> getInfo(@PathVariable("id") String id) {
        return R.ok(umClientUserService.selectUserVoById(id));
    }

    @Operation(summary = "新增客户端用户")
    @PreAuthorize("@ss.hasPermi('um:umClientUser:add')")
    @Log(title = "客户端用户", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody UmClientUser umClientUser) {
        return toAjax(umClientUserService.insertUmClientUser(umClientUser));
    }

    @Operation(summary = "修改客户端用户")
    @PreAuthorize("@ss.hasPermi('um:umClientUser:edit')")
    @Log(title = "客户端用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody UmClientUser umClientUser) {
        return toAjax(umClientUserService.updateUmClientUser(umClientUser));
    }

    @Operation(summary = "删除客户端用户")
    @PreAuthorize("@ss.hasPermi('um:umClientUser:remove')")
    @Log(title = "客户端用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable List<String> ids) {
        return toAjax(umClientUserService.deleteUmClientUserByIds(ids));
    }
}
